const mongoose = require('mongoose')
const Double = require('./double')

const Tag = mongoose.model(
  'Tag',
  new mongoose.Schema({
    _id: { type: Double },
    alarmDisabled: { type: Boolean, default: false },
    alarmRange: { type: Double, default: 0.0 },
    alarmState: { type: Double, default: -1.0 },
    alarmed: { type: Boolean, default: false },
    alerted: { type: Boolean, default: false },
    alertState: { type: String, default: '' },
    annotation: { type: String, default: '' },
    commandBlocked: { type: Boolean, default: false },
    commandOfSupervised: { type: Double, default: 0.0 },
    commissioningRemarks: { type: String, default: '' },
    description: { type: String, default: '' },
    eventTextFalse: { type: String, default: '' },
    eventTextTrue: { type: String, default: '' },
    formula: { type: Double, default: 0.0 },
    frozen: { type: Boolean, default: false },
    frozenDetectTimeout: { type: Double, default: 0.0 },
    group1: { type: String, default: '' },
    group2: { type: String, default: '' },
    group3: { type: String, default: '' },
    hihihiLimit: { type: Double, default: Number.MAX_VALUE },
    hihiLimit: { type: Double, default: Number.MAX_VALUE },
    hiLimit: { type: Double, default: Number.MAX_VALUE },
    historianDeadBand: { type: Double, default: 0.0 },
    historianPeriod: { type: Double, default: 0.0 },
    historianLastValue: { type: Double, default: null },
    hysteresis: { type: Double, default: 0.0 },
    invalid: { type: Boolean, default: true },
    invalidDetectTimeout: { type: Double, default: 300.0 },
    isEvent: { type: Boolean, default: false },
    kconv1: { type: Double, default: 1.0 },
    kconv2: { type: Double, default: 0.0 },
    location: { type: Object, default: null },
    loLimit: { type: Double, default: -Number.MAX_VALUE },
    loloLimit: { type: Double, default: -Number.MAX_VALUE },
    lololoLimit: { type: Double, default: -Number.MAX_VALUE },
    notes: { type: String, default: '' },
    origin: { type: String, default: 'supervised' },
    overflow: { type: Boolean, default: false },
    parcels: { type: Array, default: [] },
    priority: { type: Double, default: 0.0 },
    protocolDestinations: { type: Array, default: [] },
    protocolSourceASDU: { type: mongoose.Mixed, default: '' },
    protocolSourceCommandDuration: { type: Double, default: 0.0 },
    protocolSourceCommandUseSBO: { type: Boolean, default: false },
    protocolSourceCommonAddress: { type: mongoose.Mixed, default: '' },
    protocolSourceConnectionNumber: { type: Double, default: 0.0 },
    protocolSourceObjectAddress: { type: mongoose.Mixed, default: '' },
    stateTextFalse: { type: String, default: '' },
    stateTextTrue: { type: String, default: '' },
    substituted: { type: Boolean, default: false },
    supervisedOfCommand: { type: Double, default: 0.0 },
    tag: { type: String },
    timeTag: { type: Object, default: null },
    timeTagAlarm: { type: Object, default: null },
    timeTagAlertState: { type: Object, default: null },
    timeTagAtSource: { type: Object, default: null },
    timeTagAtSourceOk: { type: Object, default: null },
    transient: { type: Boolean, default: false },
    type: { type: String, default: 'digital' },
    ungroupedDescription: { type: String, default: '' },
    unit: { type: String, default: '' },
    updatesCnt: { type: Double, default: 0.0 },
    value: { type: Double, default: 0.0 },
    valueDefault: { type: Double, default: 0.0 },
    valueJson: { type: Object, default: null },
    valueString: { type: String, default: '' },
    zeroDeadband: { type: Double, default: 0.0 },
  }),
  'realtimeData'
)

module.exports = Tag
